package leetcode.dp;


/**
 * 第 N 个泰波那契数
 */
public class Tribonacci {
    public static void main(String[] args) {
        System.out.println(tribonacci(4));
    }

    public static int tribonacci(int n) {
        if (n == 0) {
            return 0;
        }
        if (n == 1 || n == 2) {
            return 1;
        }
        int f = 0, s = 1, t = 1;
        for (int i = 3; i <= n; i++) {
            int tmp = f + s + t;
            f = s;
            s = t;
            t = tmp;
        }
        return t;
    }
}
